home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / File / Trash Invisibles < prev    next >
Encoding:
Text File  |  1999-03-04  |  3.4 KB  |  176 lines  |  [TEXT/ToyS]

  1. -- Preferences
  2. property kasPrefName : "Foreign Aliases 1.0"
  3.  
  4. -- Globals
  5. global gasInfoWind -- Info window
  6. global gasInfoPos -- Position of info window
  7. global gasFoldersToDo -- The folders left to process
  8. global gasTrashed -- Number gone!
  9. global gasChecked -- Number checked!
  10.  
  11.  
  12. on open fsObjs
  13.     -- Load prefs, show window
  14.     pfLoad()
  15.     
  16.     set gasTrashed to 0
  17.     set gasChecked to 0
  18.     
  19.     set gasInfoWind to display info titled kasPrefName ¬
  20.         located at gasInfoPos ¬
  21.         message "Scanning…"
  22.     
  23.     -- Do files
  24.     set gasFoldersToDo to {}
  25.     
  26.     repeat with fsObj in fsObjs
  27.         set myInfo to (extended info for fsObj)
  28.         
  29.         if (invisible status of myInfo) then
  30.             DoOne(fsObj)
  31.         else if (system type of myInfo is "fold") then
  32.             set gasFoldersToDo to gasFoldersToDo & {fsObj}
  33.         end if
  34.     end repeat
  35.     
  36.     -- Do folders
  37.     repeat while gasFoldersToDo is not {}
  38.         -- Pop one off the end
  39.         set n to the number of items of gasFoldersToDo
  40.         set fsObj to item n of gasFoldersToDo
  41.         
  42.         if (n > 1) then
  43.             set gasFoldersToDo to items 1 through (n - 1) of gasFoldersToDo
  44.         else
  45.             set gasFoldersToDo to {}
  46.         end if
  47.         
  48.         display info gasInfoWind ¬
  49.             message ("Folders to go: " & n) ¬
  50.             at line 6 ¬
  51.             using color (15 * 32)
  52.         
  53.         -- Process it
  54.         GoDeep(fsObj)
  55.     end repeat
  56.     
  57.     display info gasInfoWind message "DONE!"
  58.     
  59.     pause for 5 with seconds timing -- Let screen wait...
  60.     
  61.     set gasInfoPos to screen location of ¬
  62.         (display info gasInfoWind with disposal)
  63.     
  64.     pfSave() -- Save window location
  65. end open
  66.  
  67.  
  68. on DoOne(fsObj)
  69.     set aFileInfo to (alias info from fsObj)
  70.     
  71.     display info gasInfoWind ¬
  72.         message "File: " & (original name of aFileInfo) ¬
  73.         at line 2
  74.     
  75.     set gasChecked to gasChecked + 1
  76.     
  77.     try
  78.         set myInfo to (extended info for fsObj)
  79.     on error
  80.         TrashFile(fsObj, "Info error.")
  81.         return
  82.     end try
  83.     
  84.     set invisible status of myInfo to false
  85.     
  86.     try
  87.         set the catalog info of fsObj to myInfo
  88.     on error
  89.         beep
  90.     end try
  91.     
  92.     TrashFile(fsObj, "Invisible")
  93.     
  94.     display info gasInfoWind ¬
  95.         message ("Checked: " & gasChecked) ¬
  96.         at line 7 ¬
  97.         using color 15
  98. end DoOne
  99.  
  100.  
  101. on TrashFile(fsObj, reason)
  102.     display info gasInfoWind ¬
  103.         message reason at line 3
  104.     
  105.     try
  106.         collate fsObj with the trasher
  107.     on error err
  108.         display info gasInfoWind ¬
  109.             message ("Error: " & err) ¬
  110.             at line 12 ¬
  111.             using color (15 * 1024)
  112.         beep
  113.     end try
  114.     
  115.     set gasTrashed to gasTrashed + 1
  116.     
  117.     display info gasInfoWind ¬
  118.         message ("Trashed: " & gasTrashed) ¬
  119.         at line 8 ¬
  120.         using color (15 * 1024)
  121. end TrashFile
  122.  
  123.  
  124. on GoDeep(foldObj)
  125.     display info gasInfoWind ¬
  126.         message "Path: " & (foldObj as string)
  127.     
  128.     set daddy to foldObj as string
  129.     
  130.     -- Do aliases
  131.     display info gasInfoWind ¬
  132.         message "Scanning aliases" at line 5
  133.     
  134.     set myItems to the entries in foldObj ¬
  135.         without whose visibility is
  136.     
  137.     repeat with myItem in myItems
  138.         try
  139.             set oneItem to (daddy & myItem) as alias
  140.             DoOne(oneItem)
  141.         on error err
  142.             display info gasInfoWind ¬
  143.                 message ("Error: " & err) ¬
  144.                 at line 13 ¬
  145.                 using color (15 * 1024)
  146.             beep
  147.         end try
  148.     end repeat
  149.     
  150.     -- Do folders
  151.     display info gasInfoWind ¬
  152.         message "Scanning subfolders" at line 5
  153.     
  154.     set myItems to the entries in foldObj ¬
  155.         whose kinds are a folder
  156.     
  157.     repeat with myItem in myItems
  158.         set gasFoldersToDo to gasFoldersToDo & {(daddy & myItem) as alias}
  159.     end repeat
  160. end GoDeep
  161.  
  162.  
  163. on pfLoad()
  164.     try
  165.         set ourPrefs to (load preference named kasPrefName)
  166.         set gasInfoPos to item 1 of ourPrefs
  167.     on error
  168.         set gasInfoPos to {0, 0}
  169.     end try
  170. end pfLoad
  171.  
  172.  
  173. on pfSave()
  174.     save preference {gasInfoPos} named kasPrefName
  175. end pfSave
  176.